package cm367;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class DataConnection {
	private String data_path = "C:\\jsf\\RoomRegistration\\Data\\";
	private BufferedReader reader;
	private BufferedWriter writer;

	public List<String> getTable(String table_name) {
		
		Properties prop = new Properties();
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		InputStream stream = loader.getResourceAsStream("cm367.properties");
		try {
			prop.load(stream);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		List<String> tmp_record = new ArrayList();
		//String table = data_path + table_name;
		String table = prop.getProperty("db_path") + table_name;
		File file = new File(table);
		if (file.exists()) {
			try {    
				FileReader fr = new FileReader(file);
				reader = new BufferedReader(fr);
				String tmp_str = null;				
				while ((tmp_str = reader.readLine()) != null) {
					tmp_record.add(tmp_str);
				}
				reader.close();
				fr.close();
			} catch (IOException ex) {
				System.out.println(ex.toString());
			}
		}
		return tmp_record;		
	}
}
